package cn.wjh.business.controller;

import cn.wjh.business.domain.vo.MailVo;
import cn.wjh.business.domain.vo.RegisterVo;
import cn.wjh.business.service.ILoginService;
import cn.wjh.business.utils.ValidationGroups;
import com.ruoyi.common.constant.Constants;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
public class LoginController extends BaseController {

	@Resource
	private ILoginService loginService;
	/*邮箱验证码登录*/
	@PostMapping("/mailLogin")
	public AjaxResult mailLogin(@RequestBody @Validated(ValidationGroups.Query.class) MailVo mailVo)
	{
		AjaxResult ajax = AjaxResult.success();
		// 生成令牌
		String token = loginService.mailLogin(mailVo);
		ajax.put(Constants.TOKEN, token);
		return ajax;
	}

	/*邮箱验证码注册*/
	@PostMapping("/mailRegister")
	public AjaxResult mailRegister(@RequestBody @Validated(ValidationGroups.Query.class) RegisterVo registerVo)
	{
		AjaxResult ajax = AjaxResult.success();
		// 生成令牌
		String token = loginService.mailRegister(registerVo);
		ajax.put(Constants.TOKEN, token);
		return ajax;
	}
}
